/*
 * @Author: your name
 * @Date: 2021-11-12 21:39:15
 * @LastEditTime: 2021-11-15 17:15:11
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\serve\app\controller\article.js
 */
/*
 * @Author: your name
 * @Date: 2021-11-09 16:30:21
 * @LastEditTime: 2021-11-10 08:33:33
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\egg-example\app\controller\home.js
 */
const Mock = require("mockjs");
const { list } = Mock.mock({
    "list|20": [{
        addresser: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, //收件人
        addressee: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, //发件人
        "theme|1": ["评论回复通知", "测试"],
        send_time: "@datetime",
    }, ],
});
const Controller = require("../core/base_controller");
class EmailController extends Controller {
    async insertList() {
            const { ctx, app } = this;
            list.forEach((item) => {
                app.mysql.insert("email", {...item });
            });
            ctx.body = "添加成功";
        }
        //获取
    async getEmail() {
            const { ctx } = this;
            try {
                const res = await ctx.service.email.getEmail();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //删除
    async delEmail() {
            const { ctx } = this;
            try {
                const res = await ctx.service.email.delEmail();
                this.success(res);
            } catch (err) {
                this.error(err.message);
            }
        }
        //批量删除
    async batchDelEmail() {
        const { ctx } = this;
        try {
            const res = await ctx.service.email.batchDelEmail();
            this.success(res);
        } catch (err) {
            this.error(err.message);
        }
    }
}

module.exports = EmailController;